package cn.tydy.controller;
import cn.tydy.dao.Dto.Dto;
import cn.tydy.pojo.Bill;
import cn.tydy.service.bill.BillService;
import com.alibaba.fastjson.JSON;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;
@Controller
@RequestMapping(value = "/sys/bill")
public class BillController {
    @Resource(name = "billService")
    private BillService billService;
    @RequestMapping("/billList.html")
    public String toBillList(Model model)  {

        List<Bill> bills=  billService.listBillAll();
/*        if (bills.size()>0){
            throw new Exception("无订单信息");
        }*/
        model.addAttribute("bills",bills);
        return "billList";
    }
    @RequestMapping(value ="/billList.do",produces = {"application/json;charset=UTF-8"})
    @ResponseBody
    public String getBillList(){
        List<Bill> bills=billService.listBillAll();
        Dto dto=new Dto();
        dto.setCode("1001");
        dto.setMessage("查询成功");
        dto.setData(bills);
        String json= JSON.toJSONString(dto);
        return json;
    }




}
